package com.cwnu.onlinemall.controller;

import com.cwnu.onlinemall.pojo.MallSpecialcommodity;
import com.cwnu.onlinemall.pojo.ServerResult;
import com.cwnu.onlinemall.service.SpecialCommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@CrossOrigin
@RestController
public class SpecialCommodityController {
    @Autowired
    SpecialCommodityService specialCommodityService;
    @RequestMapping("/specialCommodity/selectAll")
    public ServerResult selectAll(){
        if (specialCommodityService.SelectAll()!=null) {
            return new ServerResult(0, "查询成功", specialCommodityService.SelectAll());
        }else {
            return new ServerResult(1, "查询失败", null);
        }
    }

    @RequestMapping("/specialCommodity/selectByCategoryName")
    public ServerResult selectByCategoryName(String categoryName){
        if (specialCommodityService.selectByCategoryName(categoryName).size()>=1) {
            return  new ServerResult(0,"查询成功",specialCommodityService.selectByCategoryName(categoryName));
        }else {
            return new ServerResult(1, "查询失败，可能输入字符有误", null);
        }
    }

    @RequestMapping("/specialCommodity/selectById")
    public ServerResult selectById(Integer id){
        if (specialCommodityService.selectById(id)!=null) {
            return  new ServerResult(0,"查询成功",specialCommodityService.selectById(id));
        }else {
            return new ServerResult(1, "查询失败，可能输入字符有误", null);
        }
    }

    @RequestMapping("/specialCommodity/insert")
    public ServerResult insert(MallSpecialcommodity mallCommodity){
        int row=specialCommodityService.insert(mallCommodity);
        if (row>=1) {
            return  new ServerResult(0,"插入成功",row);
        }else {
            return new ServerResult(1, "插入失败，可能输入字符有误", null);
        }
    }

    @RequestMapping("/specialCommodity/update")
    public  ServerResult update(MallSpecialcommodity mallCommodity){
        int row=specialCommodityService.updateById(mallCommodity);
        if (row>=1) {
            return  new ServerResult(0,"更新成功",row);
        }else {
            return new ServerResult(1, "更新失败，可能输入字符有误", null);
        }
    }

    @RequestMapping("/specialCommodity/deleteById")
    public ServerResult delete(Integer id){
        int row=specialCommodityService.deleteById(id);
        if (row>=1) {
            return  new ServerResult(0,"删除成功",row);
        }else {
            return new ServerResult(1, "删除失败，可能输入字符有误", null);
        }
    }
}
